package pair.parking.action;

import pair.parking.bean.Car;
import pair.parking.bean.ParkingLot;
import pair.parking.common.CommonData;

import java.util.Collections;

/**
 * Create by Vic Xu on 8/24/2018
 *
 * @author Vic Xu
 */
public class SuperParkingBoy extends BaseParkingBoy {

    @Override
    public Car addCar(Car car) {
        sort();
        ParkingLot parkingLot = CommonData.packingLotList.get(0);
        if (parkingLot.isFull() && !isExist(car.getCarNumber())) {
            parkingDetail(0, parkingLot, car);
            return car;
        }
        return null;
    }

    @Override
    public void sort() {
        Collections.sort(CommonData.packingLotList, (a, b) -> {
            float result = (float) a.getCarSet().size() / (float) a.getMaxSpace() - (float) b.getCarSet().size() / (float) b.getMaxSpace();
            return (int) (result * CommonData.SORT_RATE);
        });
    }
}
